package pres.liko.iot.blackip.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pres.liko.iot.bean.R;
import pres.liko.iot.blackip.pojo.Dc3BlackIp;
import pres.liko.iot.blackip.service.BlackIpService;
import reactor.core.publisher.Mono;

import java.util.Set;

/**
 * @ClassName: BlackController
 * @Auther: liko
 * @Description:
 * @Date: 2022/11/1 16:29
 */
@RestController
@RequestMapping("/blackip")
public class BlackController {

    @Autowired
    private BlackIpService blackIpService;


    @PostMapping("/ip")
    public Mono<R<Object>> addIp(@RequestBody Mono<Dc3BlackIp> blackIpMono) {
        return blackIpService.addIp(blackIpMono);
    }

    @GetMapping("/ip")
    public Mono<R<Set<String>>> findAllEnable() {
        return blackIpService.findAllEnable();
    }

    @DeleteMapping("/ip/{id}")
    Mono<R<Object>> deleteIp(@PathVariable String id) {
        return blackIpService.deleteIp(id);
    }

    @PutMapping("/ip/{id}/{enable}")
    Mono<R<Object>> deleteIp2(@PathVariable String id, @PathVariable Integer enable) {
        return blackIpService.updateEnableById(id, enable);
    }

    @PutMapping("/ip/{id}")
    Mono<R<Object>> deleteIp3(@PathVariable String id) {
        return blackIpService.updateDeletedById(id);
    }

    @PutMapping("/ip")
    public Mono<R<Object>> updateIp(@RequestBody Mono<Dc3BlackIp> blackIpMono) {
        return blackIpService.updateIp(blackIpMono);
    }
}

